import subprocess

from fastapi import APIRouter, Form
from starlette.responses import HTMLResponse, JSONResponse
from pathlib import Path as SysPath
router = APIRouter()
@router.get("/search/")
async def search_api(q: str):
    concept_dir = SysPath("./uploads") / q
    if not concept_dir.exists():
        return JSONResponse(content={"error": "概念未找到"}, status_code=404)

    image_paths = [f"/uploads/{q}/{img.name}" for img in concept_dir.glob("*") if
                   img.suffix.lower() in [".png", ".jpg", ".jpeg", ".webp"]]
    return {"concept": q, "images": image_paths}